//
//  ProcessInfoExtension.swift
//  JKTools
//
//  Created by 姜奎 on 2024/10/16.
//

import Foundation

public
extension ProcessInfo {

    private
    struct HostInfo {
        var numCPUs: Int32 = 0

        static func getPhysicalProcessorCount() -> Int {

            var info = HostInfo()
            var size = MemoryLayout<HostInfo>.size
            let result = sysctlbyname("hw.physicalcpu",&info,&size, nil, 0)

            if result == 0 {
                return Int(info.numCPUs)
            } else {
                return -1
            }
        }
    }

    static var physicalcpu: Int = HostInfo.getPhysicalProcessorCount()

    static var ncpu: Int = processInfo.activeProcessorCount
}
